<template>
  <div class="register">
    <x-header v-show="!isWeChar">
      <div slot="default" class="common__header--title">{{pageTitle}}</div>
      <div @click="goBack" slot="overwrite-left"><img slot="icon" src="~assets/x3/ico/goback1.png" class="go-back"></div>
    </x-header>
    <!-- 渠道用户注册 -->
    <div class="register_inputDiv">
      <x-input v-model="userDto.employeeCode" required :min="StrLenth.eCodeMin" :max="StrLenth.eCodeMax" placeholder="请输入员工编码" :readonly="isReadEmployeeCode">
        <img slot="label" src="~assets/x3/channel/register/(0).png" width="18">
      </x-input>
      <x-input v-model="userDto.userName" required :min="StrLenth.userNameMin" :max="StrLenth.userNameMax" placeholder="请输入姓名" :readonly="isReadUserName">
        <img slot="label" src="~assets/x3/channel/register/(1).png" width="18">
      </x-input>
      <x-input v-model="userDto.idNumber" required :min="StrLenth.idNumberMin" :max="StrLenth.idNumberMax" placeholder="请输入证件号" :readonly="isReadIdNumber">
        <img slot="label" src="~assets/x3/channel/register/(2).png" width="18">
      </x-input>
      <!-- <x-input v-model="userDto.password" required type="password" :min="StrLenth.pwdMin" :max="StrLenth.pwdMax" placeholder="请输入密码" v-show="!haveUser">
        <img slot="label" src="~assets/x3/channel/register/(3).png" width="18">
      </x-input>
      <x-input v-model="userDto.confirmPassword" required type="password" :min="StrLenth.pwdMin" :max="StrLenth.pwdMax" placeholder="请确认密码" v-show="!haveUser">
      <img slot="label" src="~assets/x3/channel/register/(3).png" width="18">
      </x-input> -->
      <x-input v-model="userDto.mobile" required type="tel" :max="StrLenth.mobile" placeholder="请输入手机号码" :disabled="isSendOk" :readonly="isReadMobile">
        <img slot="label" src="~assets/x3/channel/register/(4).png" width="18">
      </x-input>
      <x-input v-model="userDto.imgCode" v-if="haveImgCode" :max="StrLenth.img" placeholder="请输入图形码">
        <img slot="label" src="~assets/x3/ico/ico-input-img_code.png" width="18">
        <span slot="right" class="img__code--change" @click="changeImgCode()">换一张</span>
        <img slot="right" class="img__code" :src="imgCodeSrc" @click="changeImgCode()">
      </x-input>
      <x-input v-model="userDto.mobileCode" required type="tel" :max="StrLenth.sms" placeholder="短信验证码">
        <img slot="label" src="~assets/x3/channel/register/(5).png" width="18">
        <x-button action-type="button" slot="right" mini class="linkMobileCode" @click.native="sendSmsCode" :text="sendBtnText" :disabled="isSendOk"></x-button>
      </x-input>

      <!-- 业务关系代码 -->
      <x-switch v-show="!isCanModify" :title="titleAgr" style="font-size:16px;" v-model="isAgr" :disabled="isCanModify"></x-switch>
      <div v-show="isAgr&&!isCanModify">
        <x-input style="font-size:14px;" placeholder="请输入业务关系代码" v-model="userDto.agrementNo" :required="isAgr" @on-change="changeInputAgr()" :min="StrLenth.agrMin" :max="StrLenth.agrMax" :disabled="isCanModify">
          <!-- 代理名称 -->
          <span v-show="typeof(userDto.agrementName)!='undefined' && userDto.agrementName.length<=7" slot="right" class="enterprise_name">{{userDto.agrementName}}</span>
        </x-input>
        <!-- 长-代理名称 -->
        <x-input v-show="typeof(userDto.agrementName)!='undefined' && userDto.agrementName.length>7" :value="userDto.agrementName | f_AgrName" readonly class="enterprise_name"></x-input>
        <!-- 产销人员 -->
        <selector v-show="havePMP" class="personnels" placeholder="请选择产销人员" v-model="selectedSalePerson" :options="sealesPersos" :readonly="isCanModify"></selector>
      </div>
      <div v-show="!isAgr" class="row_up_area">
        <div v-show="residentArea==true || residentArea.length==0">
          <img alt="图片" src="~assets/x3/ico/icon-addre.png" />
          <div class="remarks">
            <div class="title">请选择常驻地区</div>
            <div>我们将按照常驻地区信息分配服务机构</div>
          </div>
        </div>
        <!-- 常驻地区选择 -->
        <selector class="areaSelects" v-model="residentArea" :options="hotareas" @on-change="onChangeSelector" :readonly="isCanModify"></selector>
      </div>
    </div>

    <!-- 协议勾选 -->
    <div class="row_protocol">
      <span @click="confirmItem">
        <img v-show="isCheckProtocol" class="insure__img" src="~assets/x3/ico/check.png">
        <img v-show="!isCheckProtocol" class="insure__img" src="~assets/x3/ico/check_un.png">
      </span>
      <span class="insure__sure">
        <span @click="confirmItem">已阅读并同意</span>
        <a href="JavaScript:void(0);" @click="clauseRead('registerUserProtocol','恒华出行宝注册用户协议')">《用户协议》</a>
        <a href="JavaScript:void(0);" @click="clauseRead('setShopProtocol','恒华出行宝店铺会员服务协议')">《开店协议》</a>
      </span>
    </div>

    <!-- 显示协议的弹窗 -->
    <x-dialog v-model="showDialog" class="dialog-Einv" hide-on-blur>
      <div style="padding:10px">
        <div class="protocol_content" style="overflow-y: overlay;">
          <p align="left" v-html="readText"></p>
        </div>
      </div>
      <div>
        <x-button style="width: 100px !important;" @click.native="showDialog=false" mini type="primary">确认</x-button>
        <!-- <x-button mini>取消</x-button> -->
      </div>
    </x-dialog>

    <div class="register_errorMsg" v-show="haveError">
      <badge text="!"></badge> {{errorMessage}}
    </div>
    <!-- button -->
    <x-button type="primary" v-show="!isNextSaveBtn" :disabled="isDisabled" @click.native="submitOne()" class="register_process_btn">提交注册</x-button>
    <!-- next -->
    <x-button type="primary" v-show="isNextSaveBtn" :disabled="isDisabled" @click.native="submitTwo()" class="register_process_btn">提交注册</x-button>
  </div>
</template>
<script>
import { XHeader, XInput, XButton, Badge, XDialog, Group, XSwitch, Selector } from "vux";
import { mapState } from "vuex";
import { RouteUrl, Mutations, StrLenth, SelectorTag, Url_Key } from "src/common/const";
import Validation from "src/common/util/validation";
import { RequestUrl } from "src/common/url";
import WeChatOauth from "src/js/weChat/weChatOauth"; //引入微信授权js
export default {
  components: { XHeader, XInput, XButton, Badge, XDialog, Group, XSwitch, Selector },
  computed: mapState(["isWeChar", "user", "channel", "initUrl", "saveInsure", "isWeAuth", "shareUuid"]),
  data() {
    return {
      StrLenth: {}, //字符长度常量
      pageTitle: "注册用户",
      postUrl: RequestUrl.REGISTER_CHANNEL,//默认请求接口 - 渠道账户注册 - 默认请求无图形码接口
      userDto: {
        TYPE: "FORM",//传参类型
        registerType: "0", // 注册类型：0=wx自主/分享注册(个人用户)，1=后台注册(渠道用户)，2=分享注册(渠道用户)
        wxOpenId: "",//微信openID
        employeeCode: "", //员工编码
        isReadEmployeeCode: false,//是否只读员工编码
        userName: "", //真实姓名
        isReadUserName: false,//是否只读姓名
        idNumber: "", //身份证号
        isReadIdNumber: false,//是否只读身份证号
        // password: "", //密码
        // confirmPassword: "", //确认密码
        imgCode: "", //图形码
        mobile: "",
        isReadMobile: false,//是否只读手机号
        mobileCode: "", //验证码
        shopName: "",// 渠道名称或者叫店铺名称
        branchCode: "",//业务关系代码所属机构编码
        agrementNo: "",//输入的业务关系代码
        agrementName: "",//业务关系代码代理名称
        saleCode: "",//销售人员代码
        saleName: "",//销售人员姓名
        areaCode: "",//常驻地区编码
        areaName: "",//常驻地区名
        comCode: "",//所属部门上级编码
      },
      haveUser: false,//是否已经注册账户
      isSendOk: false, //发送按钮是否禁用
      sendBtnText: "获取验证码", //发送按钮文本内容
      imgCodeSrc: RequestUrl.GET_VALIDATE_CODE, //验证码图片路径
      haveImgCode: false, //是否需要图形码,因为默认为密码登录因此需要,动态码登录第一次不需要

      isAgr: true,  //是否有业务关系代码
      titleAgr: "有业务关系代码",
      havePMP: false,//是否需要选中产销人员
      selectedSalePerson: "",//选中的产销人员对象
      sealesPersos: [],//产销人员列表
      residentArea: "",//选中的常驻地区
      hotareas: [],//常驻地区列表
      isMounted: true,//是否第一次加载时用
      isShowAgrInfo: false,//是否显示业务关系代码相关信息
      isCanModify: false, //是否不允许修改店铺信息（业务关系代码）

      isCheckProtocol: false,//是否已勾选协议
      showDialog: false,//是否显示协议
      readText: "",//协议内容

      haveError: false, //是否显示错误
      errorMessage: "", //错误信息,
      isDisabled: false,//是否禁用提交按钮
      isNextSaveBtn: false,//是否显示下一步保存按钮
    };
  },
  filters: {
    f_AgrName(val) {
      return val.length > 17 ? val.substring(0, 18) + "..." : val;
    },
  },
  watch: {
    showDialog(cur, old) {
      if (cur) {
        $("body").css("overflow-y", "hidden");
      } else {
        $("body").css("overflow-y", "auto");
      }
    },
    //产销人员选择时设置信息
    selectedSalePerson(cur, old) {
      this.userDto.saleCode = cur.saleVocationCardNo;//销售人员编码
      this.userDto.saleName = cur.saleName;//销售人员名称
    },
    //产销人员自动选择对应的人员
    sealesPersos(cur, old) {
      //自动选择
      if (this.isMounted && this.$common.isNotEmpty(cur) && cur.length > 0) {
        for (let index = 0; index < cur.length; index++) {
          let element = cur[index];
          if (this.channel.superChannelUserDto.saleCode == element.key.saleVocationCardNo) {
            this.selectedSalePerson = element.key;//选中项对象

            this.isMounted = false;//关闭第一次使用
          }
        }
      }
    },
    //自动选择对应的常驻地区
    hotareas(cur, old) {
      if (this.$common.isNotEmpty(cur) && cur.length > 0) {
        for (let index = 0; index < cur.length; index++) {
          let element = cur[index];
          if (this.$common.isNotEmpty(this.channel.superChannelUserDto.areaCode) && this.$common.isNotEmpty(element.key)
            && this.channel.superChannelUserDto.areaCode === element.key.areaCode) {
            this.residentArea = element.key;//选中项为key

            //注册类型不为个人的才需要判断是否允许修改店铺信息（业务关系代码）
            if (this.$common.isNotEmpty(this.channel.superChannelUserDto.registerType)
              && this.channel.superChannelUserDto.registerType != "0"
              && this.$common.isNotEmpty(this.channel.superChannelUserDto.canModify)
              && this.channel.superChannelUserDto.canModify == "0") {

              this.isCanModify = true;//禁改
            }
            break;
          }
        }
      }
    },
    //业务关系代码变化后清空代理名称
    'userDto.agrementNo': {
      handler(cur, old) {
        if (cur != old) {
          this.userDto.agrementName = "";
        }
      }
    },
    //有无关系代码切换按钮
    isAgr(cur, old) {
      if (cur) {
        // this.isDisabled = true;//禁用按钮激活
        this.changeInputAgr();
        this.titleAgr = "有业务关系代码";
      } else {
        this.titleAgr = "无业务关系代码";
        if (this.$common.isEmpty(this.hotareas) || this.hotareas.length < 2) {
          //查询所有常驻地区
          this.$common.storeCommit(this, Mutations.GET_ALL_HOT_AREA, this);
        }
        // this.isDisabled = false;//提交按钮激活
        this.isNextSaveBtn = false;//隐藏下一步按钮
      }
    },
    residentArea(cur, old) {
      console.log("cur=" + cur + ",old=" + old);
    },
  },
  methods: {
    goBack() {
      //返回
      this.$common.goBack(this);
    },
    changeImgCode() {
      this.imgCodeSrc = RequestUrl.GET_VALIDATE_CODE + "?a=" + Math.random();
    },
    // 发送验证码
    sendSmsCode() {
      /**
       * 发送验证码,返回data.msg=信息,data.state=0表示成功
       * isSendOk,true=禁用(disabled=true)
       * sendBtnText,验证码按钮文本显示内容
       */
      let imageCode = null;
      if (this.haveImgCode) {
        //需要图形码时传递参数
        imageCode = this.userDto.imgCode;
        //校验-图形码
        let msg = Validation.isImgCode(imageCode);
        if (msg != null) {
          this.errorMessage = msg;
          this.haveError = true;
          return;
        }
      }
      this.$common.sendSMS(this, this.userDto.mobile, imageCode, this.isSendOk, this.pageTitle);
    },
    //常驻地区选项更改事件
    onChangeSelector() {
      //过滤无效选项的key值
      this.hotareas = this.$common.filterSelect(this.residentArea, this.hotareas);
    },
    //业务关系代码更改内容事件
    changeInputAgr() {
      if (this.isAgr) {
        if (this.$common.isNotEmpty(this.userDto.agrementNo) && this.userDto.agrementNo.length >= StrLenth.agrMin && this.userDto.agrementNo.length <= StrLenth.agrMax) {
          // this.isDisabled = false;//启用第一步按钮

          if (this.isMounted) {
            //查询业务关系代码
            this.queryAgreementNo(this.userDto.agrementNo);
          }
        }
        // else {
        //   this.isDisabled = true;//禁用第一步按钮
        // }
        this.userDto.agrementName = "";//代理名称
        this.havePMP = false;//是否显示产销人员列表
        this.selectedSalePerson = "";//选择的产销人员
        this.sealesPersos = [];//产销人员列表

        this.isNextSaveBtn = false;//隐藏下一步按钮
      }
    },
    //提交注册第一步
    submitOne() {
      //表单提交校验
      this.haveError = !this.checkFormData();
      if (this.haveError) {
        return;//信息不完整
      }

      if (this.isAgr) {
        //有业务关系代码时 - 查询业务关系代码
        this.queryAgreementNo(this.userDto.agrementNo);
      } else {
        //无业务关系代码时 - 选择常住地
        this.userDto.branchCode = this.residentArea.branchCode;//常驻地区默认业务关系代码所属机构编码
        this.userDto.agrementNo = this.residentArea.agreementNo;//常驻地区默认业务关系代码
        this.userDto.saleCode = this.residentArea.saleCode;
        this.userDto.saleName = this.residentArea.saleName;
        this.userDto.areaCode = this.residentArea.areaCode;//常驻地区编码
        this.userDto.areaName = this.residentArea.areaName;//常驻地区编码

        if (this.$common.isEmpty(this.userDto.agrementNo) || this.userDto.agrementNo == SelectorTag.keyNull
          || this.$common.isEmpty(this.userDto.areaCode) || this.$common.isEmpty(this.userDto.areaName)) {
          this.errorMessage = "请正确选择地区"; this.haveError = true; return;
        }
        // this.userDto.branchCode = this.residentArea.branchCode;//常驻地区默认业务关系代码所属机构编码
        // this.userDto.areaCode = this.residentArea.areaCode;//常驻地区编码
        // this.userDto.areaName = this.residentArea.areaName;//常驻地区编码

        // if (this.$common.isEmpty(this.userDto.areaCode) || this.$common.isEmpty(this.userDto.areaName)) {
        //   this.errorMessage = "请正确选择地区"; this.haveError = true; return;
        // }
        //常住地注册直接提交
        this.userDto.type = "select";
        this.userDto.shopName = this.userDto.userName;//设置店铺/渠道层级名称
        this.subForm(this.postUrl, this.userDto);
      }
    },
    //确认注册（一定是输入的业务关系代码）
    submitTwo() {
      //表单提交校验
      this.haveError = !this.checkFormData();
      if (this.haveError) {
        return;//信息不完整
      }

      if (this.$common.isEmpty(this.userDto.agrementNo)) {
        this.errorMessage = "请输入业务关系代码"; this.haveError = true; return;
      }
      //转大写
      this.userDto.agrementNo = this.userDto.agrementNo.toUpperCase();

      if (this.havePMP) {
        this.userDto.saleCode = this.selectedSalePerson.saleVocationCardNo;//销售人员编码
        this.userDto.saleName = this.selectedSalePerson.saleName;//销售人员名称
        if (this.$common.isEmpty(this.userDto.saleCode) || this.$common.isEmpty(this.userDto.saleName)) {
          this.errorMessage = "请选择销售人员"; this.haveError = true; return;
        }
      }
      //有业务关系代码注册提交
      this.userDto.type = "input";
      this.userDto.shopName = this.userDto.userName;//设置店铺/渠道层级名称
      this.subForm(this.postUrl, this.userDto);
    },
    //提交请求
    subForm(url, data) {
      let _this = this;
      _this.$common.storeCommit(_this, Mutations.UPDATE_LOADING_STATUS, true);
      _this.$http.post(url, data).then(function (res) {
        _this.$common.storeCommit(_this, Mutations.UPDATE_LOADING_STATUS, false);
        if (res.state != 0) {
          _this.changeImgCode();//更换图形验证码
          _this.errorMessage = res.result;
          _this.haveError = true; //显示错误信息标签
          _this.haveImgCode = true; //启动图形码同时校验
          if (res.result.indexOf("已被") >= 0) {
            _this.isSendOk = false; //启用发送按钮和手机号输入
            _this.sendBtnText = "获取验证码";
            //清除验证码倒计时
            _this.$common.clearTimeOutForSms();
          }
          //禁改店铺信息（业务关系代码）时，无需再查询业务关系代码，防止提交表单错误后userdto数据清空
          if (_this.isCanModify
            || _this.isNotEmpty(_this.userDto.agrementNo)
            || (_this.isNotEmpty(_this.userDto.areaCode) && _this.isNotEmpty(_this.userDto.areaName))) {
            _this.isNextSaveBtn = true;//显示下一步
          } else {
            _this.isNextSaveBtn = false;//隐藏下一步按钮
          }
          return;
        }
        //清除推荐人信息
        _this.$common.storeCommit(_this, Mutations.SET_REFEREE_DATA, false);
        _this.$common.storeCommit(_this, Mutations.REF_SHARE_U_UID, "");

        if (_this.isWeChar) {
          //微信浏览器需要授权后将微信信息设置到当前账户

          //保存当前渠道账户的usecode信息
          _this.$common.storeCommit(_this, Mutations.SAVE_CHANNEL_USER_CODE, res.result.userCode);
          //微信授权
          WeChatOauth.weChatOauth(_this, false, res.result.userCode);
        } else {
          //普通浏览器直接注册
          //保存USER_INFO信息
          _this.$common.storeCommit(_this, Mutations.SAVE_USER_INFO, res.result);
          _this.$common.goUrl(_this, RouteUrl.MY);
        }
      });
    },
    //表单提交校验
    checkFormData() {
      //已勾选协议
      if (!this.isCheckProtocol) {
        this.errorMessage = "请勾选协议"; return false;
      }
      //校验-员工编码
      let msg = Validation.isEmployeeCode(this.userDto.employeeCode);
      if (msg != null) {
        this.errorMessage = msg; return false;
      }
      //校验-姓名
      msg = Validation.isUserNameA_9(this.userDto.userName);
      if (msg != null) {
        this.errorMessage = msg; return false;
      }
      //校验-身份证号码
      if (Validation.isEmpty(this.userDto.idNumber)) {
        this.errorMessage = "请输入身份证号码"; return false;
      }
      if (!Validation.isIdNumber(this.userDto.idNumber)) {
        this.errorMessage = "请输入有效的身份证号码"; return false;
      }
      // //新账户校验-密码
      // if (!this.haveUser) {
      //   msg = Validation.isPassword(this.userDto.password);
      //   if (msg != null) {
      //     this.errorMessage = msg; return false;
      //   }
      //   if (this.userDto.password != this.userDto.confirmPassword) {
      //     this.errorMessage = "密码不一致"; return false;
      //   }
      // }
      //校验-图形码
      if (this.haveImgCode) {
        // //渠道注册 & 图形码
        this.postUrl = RequestUrl.REGISTER_CHANNEL_IMG;
        this.userDto.imgCode = this.userDto.imgCode;
        //校验-图形码
        msg = Validation.isImgCode(this.userDto.imgCode);
        if (msg != null) {
          this.errorMessage = msg; return false;
        }
      }
      //校验-手机号
      msg = Validation.isPhone11(this.userDto.mobile);
      if (msg != null) {
        this.errorMessage = msg; return false;
      }
      //校验-手机验证码
      msg = Validation.isSmsCode(this.userDto.mobileCode);
      if (msg != null) {
        this.errorMessage = msg; return false;
      }

      //验证无误
      return true;
    },
    //查询业务关系代码
    queryAgreementNo(agrementNo) {
      this.userDto.agrementNo = agrementNo;//业务关系代码，注意变量名区别
      this.userDto.agrementName = "";//代理名称
      this.havePMP = false;//是否显示产销人员列表
      this.selectedSalePerson = "";//选择的产销人员
      this.sealesPersos = [];//产销人员列表

      if (this.$common.isEmpty(this.userDto.agrementNo)) {
        this.errorMessage = "请输入业务关系代码"; this.haveError = true; return;
      }
      //大写转换
      this.userDto.agrementNo = this.userDto.agrementNo.toUpperCase();

      if (this.userDto.agrementNo == "CHQ003514") {
        this.errorMessage = "业务关系代码被禁用，请联系销售人员"; this.haveError = true; return;//显示错误信息
      }

      let _this = this;
      let data = { TYPE: "FORM", agreementNo: this.userDto.agrementNo };//注意接口参数名称区别
      _this.$common.storeCommit(_this, Mutations.UPDATE_LOADING_STATUS, true);
      _this.$http.post(RequestUrl.FIND_AGREEMENT_NO_OF_SHOP, data).then(function (res) {
        _this.$common.storeCommit(_this, Mutations.UPDATE_LOADING_STATUS, false);
        if (res.state != 0) {
          _this.errorMessage = res.result; _this.haveError = true; return;//显示错误信息
        }

        //注册类型不为个人的才需要判断是否允许修改店铺信息（业务关系代码）
        if (_this.$common.isNotEmpty(_this.channel.superChannelUserDto.registerType)
          && _this.channel.superChannelUserDto.registerType != "0"
          && _this.$common.isNotEmpty(_this.channel.superChannelUserDto.canModify)
          && _this.channel.superChannelUserDto.canModify == "0") {

          _this.isCanModify = true;//禁改
        }

        _this.isNextSaveBtn = true;//显示下一步
        let prpLmAgent = res.result.prpLmAgentList[0];//业务关系代码对象

        _this.userDto.branchCode = prpLmAgent.branch;//业务关系代码所属机构编码
        if (_this.$common.isNotEmpty(prpLmAgent.agentName)) {
          _this.userDto.agrementName = prpLmAgent.agentName;// 代理名称
        }
        if (res.result.selectSalePerson) {
          _this.sealesPersos = _this.getSealesPersos();//四川和广东地区，查询产销人员
          _this.havePMP = true;//显示产销人员选择
        } else {
          //非四川和广东地区无需选择代销人员
          _this.havePMP = false;//隐藏产销人员选择

          _this.isMounted = false;//非广东四川地区的业务关系代码使用后  直接关闭第一次使用
          return;
        }
      });
    },
    //根据业务关系代码获取销售人员信息
    getSealesPersos() {
      let array = [];
      //查询机构信息来匹配销售人员信息
      let _this = this;
      let data = { TYPE: "FORM", agreementNo: _this.userDto.agrementNo };//注意接口参数名称区别
      _this.$common.storeCommit(_this, Mutations.UPDATE_LOADING_STATUS, true);
      _this.$http.post(RequestUrl.FIND_SEALES_PERSOS, data).then(function (res) {
        _this.$common.storeCommit(_this, Mutations.UPDATE_LOADING_STATUS, false);
        if (res.state == 0 && !_this.$common.isEmpty(res.result)) {
          //有销售人员信息
          let lists = res.result.sealesPersos;
          for (var i = 0, l = lists.length; i < l; i++) {
            if (_this.$common.isEmpty(lists[i].saleName)) {
              _this.errorMessage = "请配置销售人员名称";
              _this.haveError = true;
              return;
            }
            if (_this.$common.isEmpty(lists[i].saleVocationCardNo)) {
              _this.errorMessage = "请配置销售人员编码";
              _this.haveError = true;
              return;
            }
            let obj = { key: lists[i], value: lists[i].saleName + "-" + lists[i].saleVocationCardNo };
            array.push(obj);//销售人员列表
          }
        }
      });
      return array;
    },
    //协议勾选
    confirmItem() {
      this.isCheckProtocol = !this.isCheckProtocol;
      if (this.isCheckProtocol) {
        this.errorMessage = "";
        this.haveError = false;
        return;
      }
    },
    //协议展示
    clauseRead(planId, clauseTitle) {
      let query = {
        _this: this,
        TYPE: "FORM",
        planId: planId,
        clauseTitle: clauseTitle
      }
      this.$common.storeCommit(this, Mutations.CUR_CLAUSE_TITLE_ONE, query);
      this.showDialog = true;
    },
    //触发非空校验
    valCellInput() {
      $(".weui-input").focus();
      $(".weui-input").blur();
    },
  },

  mounted() {
    document.title = this.pageTitle;
    this.StrLenth = StrLenth; //字符长度常量
    this.$init.subPageInit(this);
    //初始验证码倒计时
    this.$common.clearTimeOutForSms();

    //所属部门--上级信息
    let superUser = this.channel.superChannelUserDto;
    if (this.$common.isEmpty(superUser.userCode)) {
      this.isDisabled = true;//非正常连接的禁止提交表单
      this.$common.goBack(this);
      return;
    }
    // 注册类型：0=wx自主/分享注册(个人用户)，1=后台注册(渠道用户)，2=分享注册(渠道用户)
    if (this.$common.isNotEmpty(superUser.registerType)) {
      switch (superUser.registerType) {
        case "1":
          //上级为后台注册的渠道用户时，当前注册用户为最后一级渠道
          this.userDto.registerType = "2";
          break;
        case "0":
        case "2":
          //上级为个人或分享渠道用户时，当前注册为个人账户
          this.userDto.registerType = "0";
          break;
        default: break;
      }
    }
    //设置上级渠道用户编码
    this.userDto.comCode = superUser.userCode;

    //有业务关系代码时设置业务关系代码触发自动选择功能
    if (this.$common.isNotEmpty(superUser.agrementNo)) {
      this.userDto.agrementNo = superUser.agrementNo;//常驻地区默认业务关系代码
    }

    if (this.$common.isNotEmpty(superUser.areaCode) && this.$common.isEmpty(superUser.agrementNo)) {
      this.isAgr = false;//常住地
      this.isMounted = false;//选择常住地的直接关闭第一次使用
      this.userDto.areaCode = superUser.areaCode;//将上级渠道用户的常住地代码设置为当前用户默认的常住地编码
      this.userDto.areaName = superUser.areaName;//将上级渠道用户的常住地名称设置为当前用户默认的常住地名称
    }

    if (this.user.isLogin) {
      if (this.$common.isNotEmpty(this.user.userDto.wxOpenId)) {
        if (this.$common.isNotEmpty(this.user.userDto.storeFlag) && this.user.userDto.storeFlag == "1") {
          this.isDisabled = true;//禁止提交表单
          this.$common.showMsg(this, "您已经是店主，无需重复开店！", "red;", true);
        } else {
          this.isDisabled = false;//可点击按钮提交表单
          //微信账户已登录
          this.userDto.wxOpenId = this.user.userDto.wxOpenId;
          if (this.$common.isNotEmpty(this.user.userDto.employeeCode)) {
            //自动读取当前账户员工编码
            this.userDto.employeeCode = this.user.userDto.employeeCode;
            this.isReadEmployeeCode = true;//控制员工编码只读
          }
          if (this.$common.isNotEmpty(this.user.userDto.userName)) {
            //自动读取当前账户姓名
            this.userDto.userName = this.user.userDto.userName;
            this.isReadUserName = true;//控制姓名只读
          }
          if (this.$common.isNotEmpty(this.user.userDto.idNumber)) {
            //自动读取当前账户证件号码
            this.userDto.idNumber = this.user.userDto.idNumber;
            this.isReadIdNumber = true;//控制证件号只读
          }
          if (this.$common.isNotEmpty(this.user.userDto.mobile)) {
            //自动读取当前账户手机号码
            this.userDto.mobile = this.user.userDto.mobile;
            this.isReadMobile = true;//控制手机号只读
          }
        }
      } else {
        //普通浏览器账户
        this.isDisabled = true;//禁止提交表单
        this.$common.showMsg(this, "您已登录，请注销登录后进入！", "red;", true);
      }
    } else {
      this.isDisabled = false;//可点击按钮提交表单
    }
  }
};
</script>
<style lang="scss" scoped>
//input区域
.register_inputDiv {
  // .weui-cells {
  //   margin-top: 0px !important;
  // }
  // .weui-btn_disabled.weui-btn_primary {
  //   background-color: lightgray !important;
  // }
  // .weui-cells:after {
  //   border-bottom: 0px !important;
  // }

  margin: 10px auto;
  width: 95%;
  height: auto;
  border-radius: 5px;
  background-color: white;
  .weui-cell {
    border-top: 1px solid #efefef;
  }
  .weui-cell:before {
    border-top: 0px;
  }
  .weui-cell {
    .weui-cell__hd {
      img {
        padding-right: 10px;
        display: block;
      }
    }
  }

  //关系代码公司名称
  .enterprise_name {
    color: #c8161d;
    font-size: 14px;
  }
  //产销人员选项
  .personnels {
    .weui-cell__bd {
      .weui-select {
        color: #c8161d;
      }
    }
  }

  //常驻地区
  .row_up_area {
    width: 100%;
    height: 60px;
    border-radius: 5px;
    background-color: white;
    img {
      display: block;
      width: 20px;
      height: 20px;
      float: left;
      padding: 18px 0px 0px 15px;
    }
    //选择常驻地区说明
    .remarks {
      display: block;
      float: left;
      width: 70%;
      height: 50px;
      line-height: 21px;
      font-size: 12px;
      padding: 10px 0px 0px 15px;
      color: #a9a9a9;
      .title {
        color: gray;
        font-size: 15px;
      }
    }
    //常驻地区列表
    .areaSelects {
      position: absolute;
      display: block;
      float: right;
      width: 95%;
      height: 60px;
      line-height: 60px;
      border: 0px;
      border-top: 1px solid #efefef;
    }
  }

  //图形码
  .img__code {
    width: 80px;
    height: 31px;
    margin-left: 3px;
    vertical-align: middle;
  }

  //换一张图形码
  .img__code--change {
    margin-left: 3px;
    vertical-align: middle;
    font-size: 14px;
  }

  //获取验证码按钮
  .linkMobileCode {
    padding: 0px;
    width: 80px;
    height: 28px;
    line-height: 28px;
    font-size: 12px;
    color: #c8161d;
    border: 1px solid #c8161d;
    background-color: white;
  }
}

//注册按钮
.register_process_btn {
  width: 95% !important;
  font-size: 20px !important;
}

.register_errorMsg {
  color: red;
  font-size: 14px;
  margin-left: 10px;
  line-height: 30px;
  width: 90%;
  margin-bottom: 10px;
}

//修改默认按钮失效时背景颜色
.weui-btn_disabled.weui-btn_primary {
  background-color: #cfcfcf;
}

//修改默认badge位置
.vux-badge-single {
  margin-top: -2px;
}

//协议
.row_protocol {
  margin: 15px auto;
  width: 95%;
  font-size: 14px;
  img {
    width: 14px;
    height: auto;
    float: left;
    margin: 4px 5px 0px 16px;
  }
  span {
    line-height: 18px;
    color: #b1b1b1;
  }
  a {
    color: #c8161d;
    text-decoration: none;
  }
}

.protocol_content {
  border-color: aliceblue;
  white-space: pre-wrap;
  vertical-align: top;
  width: 100%;
  font-size: 15px;
  height: 75vh;
  font-family: Microsoft YaHei;
  overflow-y: scroll; // border: 1px solid #f3f3f3;
  font: 400 14.3333px Arial;
}
.dialog-Einv {
  // padding: 15px !important;
  .weui-dialog {
    max-width: 90% !important;
  }
}
</style>
